package com.zeus.gen.base.dto;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liuwei
 * @date 2018/8/16 10:40
 */
public class ResultDto extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ResultDto() {
        put("code", 0);
    }

    public static ResultDto error() {
        return error(500, "未知异常！");
    }

    public static ResultDto error(String msg) {
        return error(500, msg);
    }

    public static ResultDto error(int code, String msg) {
        ResultDto resultDto = new ResultDto();
        resultDto.put("code", code);
        resultDto.put("msg", msg);
        return resultDto;
    }

    public static ResultDto ok(String msg) {
        ResultDto resultDto = new ResultDto();
        resultDto.put("msg", msg);
        return resultDto;
    }

    public static ResultDto ok(Map<String, Object> map) {
        ResultDto resultDto = new ResultDto();
        resultDto.putAll(map);
        return resultDto;
    }

    public static ResultDto ok() {
        return new ResultDto();
    }

    @Override
    public ResultDto put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
